import os
import numpy as np
from utils2 import *
import random

anchor_referenceLabel_path = 'E:/Research/2020ContrastiveLearningForSceneLabel/Data/20210329ExperimentData/round2/anchorReferenceLabel_method2_exp2.txt'
anchorImg_path = 'E:/Research/2020ContrastiveLearningForSceneLabel/Data/20210329ExperimentData/round2/anchorImgs_method2_exp2'

sample_percent = 1

supplementPath = 'E:/Research/2020ContrastiveLearningForSceneLabel/Data/20210329ExperimentData/round2/supplementAlertingPos_%dpercent.txt'%(int(100 * sample_percent))

f = open(anchor_referenceLabel_path,'r')
lines = f.readlines()
f.close()
rf_label_anchor = [int(i[0]) for i in lines]
rf_label_anchor = np.array(rf_label_anchor)

sampleNum = 16
anchor_pos_list, anchor_neg_list = getAnchorPosNegIdx3(anchorImg_path, sampleNum = sampleNum, sample_interval = 2)
anchor_idx = [anchor_pos_list[i][0] for i in range(len(anchor_pos_list))]
anchor_idx = np.array(anchor_idx)

straight_idx = anchor_idx[rf_label_anchor == 1]
turn_idx = anchor_idx[rf_label_anchor == 2]
alerting_idx = anchor_idx[rf_label_anchor == 3]

straight_and_turn_idx = list(straight_idx) + list(turn_idx)
alerting_idx = list(alerting_idx)

sample_num = int(sample_percent * len(alerting_idx))


f = open(supplementPath, 'w')
f.write('# only add positive samples of all alertings, %d %% alerting are sampled \n'%(int(100 * sample_percent)))
for i in alerting_idx:
    f.write('%d: '%i) # 写锚点
    tmp = set(alerting_idx) - set([i])
    tmp = list(tmp)
    if sample_num == len(alerting_idx):
        sample_num -= 1
    cur_sample = random.sample(tmp, sample_num)
    for j in cur_sample:
        f.write('%d '%j)
    f.write(': \n')
f.close()